﻿namespace WebPacker.Tests.Helpers
{
	using System.IO;
	using NUnit.Framework;
	using WebPacker.Helpers;

	[TestFixture]
	public class VirtualPathHelperTest
	{
		[Test]
		public void CombinePath(
			[Values(@"c:\temp", @"c:\temp\")]
			string path1,
			[Values(@"path", @"\path")]
			string path2)
		{
			var expected = @"c:\temp\path".Replace('\\', Path.DirectorySeparatorChar);
			path1 = path1.Replace('\\', Path.DirectorySeparatorChar);
			path2 = path2.Replace('\\', Path.DirectorySeparatorChar);

			Assert.AreEqual(expected, VirtualPathHelper.CombinePath(path1, path2));
		}

		[Test]
		public void CombineUri(
			[Values(@"http://localhost", @"http://localhost/")]
			string path1,
			[Values(@"index.html", @"/index.html")]
			string path2)
		{
			Assert.AreEqual(@"http://localhost/index.html", VirtualPathHelper.CombineUri(path1, path2));
		}

		[Test, Sequential]
		public void EqualsTest(
			[Values(@"\webapp\test")]
			string path1,
			[Values(@"\webaPP\TEst")]
			string path2)
		{
			Assert.IsTrue(VirtualPathHelper.Equals(path1, path2));
		}

		[Test]
		public void NormalizePathTest(
			[Values(@"c:\webapp/app", @"c:/webapp/app")]
			string path)
		{
			Assert.AreEqual(@"c:\webapp\app", VirtualPathHelper.NormalizePath(path));
		}

		[Test]
		public void ToVirtualPathTest(
			[Values(@"c:\webapp\app\content\script1.css", "~/content/script1.css")]
			string path)
		{
			// for test purpose
			VirtualPathHelper.ApplicationVirtualPath = "/app";
			VirtualPathHelper.ApplicationPhysicalPath = @"c:\webapp\app";

			Assert.AreEqual("/app/content/script1.css", VirtualPathHelper.ToVirtualPath(path));
		}

		[Test]
		public void ToPhisicalPath(
			[Values(@"c:\webapp\app\content\script1.css", "~/content/script1.css")]
			string path)
		{
			VirtualPathHelper.ApplicationPhysicalPath = @"c:\webapp\app";
			Assert.AreEqual(@"c:\webapp\app\content\script1.css", VirtualPathHelper.ToPhisicalPath(path));
		}
	}
}
